package com.mystudy;

/**
 * 在HDFS上读取文件内容
 */
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

public class ReadHDFSFile {
    public static void main(String[] args) throws Exception{
        Configuration conf = new Configuration();
        //配置NameNode地址
        URI uri = new URI("hdfs://192.168.30.130:8020");
        //指定用户名，获取FileSystem对象
        FileSystem fs = FileSystem.get(uri,conf,"hadoop");
        //定义文件路径
        Path dfs = new Path("/17124080120/test5.txt");
        FSDataInputStream fis = fs.open(dfs);
        IOUtils.copyBytes(fis,System.out,4096,true);
    }
}
